<!--
	Carnegie Mellon University
	School of Computer Science
	MSIT eBusiness Technology

	Team 8 - Infinity (2011 Spring)
	infinity-team8@googlegroups.com

	Professor: Jeffrey L. Eppinger
	Program Faculty: Sujata Telang
-->

<jsp:include page="employee-template-top.jsp" />
<jsp:include page="employee-topnav.jsp" />
<%@ page import="databean.TransactionBean" %>
<%@ page import="model.TransactionDAO" %>
<%@ page import="model.FundDAO" %>
<%@ page import="model.CustomerDAO" %>


<div id="header">
	<h1>Transaction History</h1>
</div>
<jsp:include page="employee-sidebar.jsp" />

<div id="content">
<div id="form-wrapper">
<table id="minimal" summary="display transaction history">
<thead>
	<tr>
		<th scope="col"> </th>
		<th scope="col">ID</th>
		<th scope="col">Customer</th>
		<th scope="col">Fund Symbol</th>
		<th scope="col">Execute Date</th>
		<th scope="col">Share</th>
		<th scope="col">Share Price</th>
		<th scope="col">Type</th>
		<th scope="col">Amount</th>									
	</tr>
</thead>
<tbody>


<%
	TransactionBean[] transactions = (TransactionBean[]) request.getAttribute("transactionList");
	TransactionDAO transactionDAO = new TransactionDAO();
	FundDAO fundDAO = new FundDAO();
	CustomerDAO customerDAO = new CustomerDAO();
%>

	

<%
	for (TransactionBean transaction : transactions) {
		
		if (transaction.getExecuteDate()==null) {
			
			String fundSymbol;
			if (transaction.getFundID()==0) {
				fundSymbol = "";
			} else {
				fundSymbol = fundDAO.lookup(transaction.getFundID()).getSymbol();
			}
			
			String sharePrice = "";
			String shares, amount;
			if (transaction.getTransactionType().equals("deposit") || transaction.getTransactionType().equals("request")
					|| transaction.getTransactionType().equals("buy")) {
				//deposit, request, buy
				shares = "";
				amount = "$" + transactionDAO.getAmountFormatted(transaction.getTransactionID());
			} else {
				//sell
				shares = transactionDAO.getSharesFormatted(transaction.getTransactionID());
				amount = "";
			}
%>
	<tr class="italic">
	<td style="width:1px; background-color:#FFCC33"></td>
	<td><%=transaction.getTransactionID()%></td>
	<td><%=customerDAO.lookup(transaction.getCustomerID()).getUserName()%></td>
	<td><%=fundSymbol%></td>
	<td></td>
	<td><%=shares%></td>
	<td><%=sharePrice%></td>
	<td><%=transaction.getTransactionType()%></td>
	<td><%=amount%></td>
	</tr>
<%
		}
	}
%>



<%
	for (TransactionBean transaction : transactions) {
		
		if (transaction.getExecuteDate()!=null) {
			
			String fundSymbol;
			if (transaction.getFundID()==0) {
				fundSymbol = "";
			} else {
				fundSymbol = fundDAO.lookup(transaction.getFundID()).getSymbol();
			}
			
			String shares, sharePrice;
			if (transaction.getTransactionType().equals("deposit") || transaction.getTransactionType().equals("request") ) {
				shares = "";
				sharePrice = "";
			} else {
				shares = transactionDAO.getSharesFormatted(transaction.getTransactionID());
				sharePrice = "$" + transactionDAO.getSharePriceFormatted(transaction.getTransactionID());
			}
			
%>
	<tr>
	<td style="width:1px; background-color:#92B901"></td>
	<td><%=transaction.getTransactionID()%></td>
	<td><%=customerDAO.lookup(transaction.getCustomerID()).getUserName()%></td>
	<td><%=fundSymbol%></td>
	<td><%=transaction.getExecuteDate()%></td>
	<td><%=shares%></td>
	<td><%=sharePrice%></td>
	<td><%=transaction.getTransactionType()%></td>
	<td>$<%=transactionDAO.getAmountFormatted(transaction.getTransactionID())%></td>
	</tr>
<%
		}
	}
%>

</tbody>
</table>
<br />
<p class="small"><span style="color:#D1563B">**</span> Status legend : Complete = <span style="color:#92B901">green</span> / Pending = <span style="color:#FFCC33">yellow</span></p>
<p class="small"><span style="color:#D1563B">**</span> For deposit and request, shares and share price are left blank.</p>
</div>
</div>
<jsp:include page="footer.jsp" />
